/* 获取菜单树 */
$(document).ready(function () {
    let setting = $.zTree.setting({
        check: true,
        showIcon: false,
        callback: function (e, treeId, treeNode) {
            zTree.checkNode(treeNode, !treeNode.checked, true);
        }
    })

    let userId = $("#userId").val();
    $.zTree.initTree({
        url: "/base/role/user/zTree/" + userId,
        initCallback: function (res) {
            zTree = $.fn.zTree.init($("#tree"), setting, res.data);
            sitFolderTree = $.fn.zTree.getZTreeObj("tree");
            sitFolderTree.expandAll(true);
        },
    })
});

//获取checkbox的值
layui.use('form', function () {
    form = layui.form;
    form.on('submit(sub)', function (data) {
        let roleIds = $.zTree.getCheckedId("tree");
        let userId = $("#userId").val();

        let subData = {};
        subData.userId = userId;
        subData.roleId = roleIds;

        $.http.post("/base/role/user", subData, function (res) {
            $.msg.msgOkModel(res.msg);
        });
        return false;
    });
});
